/**
 * 功能:个人信息页面展示
 * 创建日期: 2012-03-19
 * 创建人: 全轩
 * 功能修正说明:
 * 		
 */

if(!this.ProfileWin)
{
	this.ProfileWin = {};
}


(function(){
	if(!ProfileWin.win)
	{
		ProfileWin.win = Ti.UI.createWindow({				
				backgroundColor : '#f2f2f2',
				layout : 'absolute'
			});
	}
	
	//当前授权用户的uid
	ProfileWin.uid = null;
	
	//父窗体
	ProfileWin.parentwin = null;
	
	/**
	 * 根据当前授权用户的信息,展示所有的个人信息
	 */
	if(typeof ProfileWin.Layout !== 'function')
	{
		ProfileWin.Layout = function(info) 
		{
			info = JSON.parse(info);
			Ti.API.info(info);
			ProfileWin.win = Ti.UI.createWindow({				
				backgroundColor : '#f2f2f2',
				layout : 'absolute'
			});
			//头像信息
			var hdView = function() {
				var hd_view = Ti.UI.createView({
					id:'hd_view',
					height : 'auto',	
					top:'2px',				
				});
				//头像			
				var avator = Ti.UI.createImageView({
					image : info.profile_image_url, 
					width:60,
					height:60,
					left:5,
					top:0,		
				});
				hd_view.add(avator);
				//昵称
				var name = Ti.UI.createLabel({
					text : info.screen_name,
					height:'auto',
					color:'#333',
					left : 70,
					font : {fontSize : 18,fontWeight:'bold'},
				});
				var seximage = Ti.UI.createLabel({
					backgroundImage: info.gender == 'm' ? 'images/form/statuses/icon_male.png':'images/form/statuses/icon_female.png',
					left:130,
					width:13,
					height:13,
				});
				hd_view.add(seximage);
				hd_view.add(name);
				//关注状态
				var follow_status_txt = info.following ? '已关注' : '加关注';				
				var followBtn = Ti.UI.createButton({
					title : follow_status_txt,
					backgroundImage:'images/form/statuses/button_comment_on.png',
					width:60,
					height:28,
					right:10,
					font : {fontSize : 14},
				});
				hd_view.add(followBtn);
			
				return hd_view;
			};
				
			ProfileWin.win.add(hdView());
			
			var profileView = function() {
				var pro_view = Ti.UI.createView({
					left : 10,
					right : 10,
					top : 70,
					height : 'auto',
					borderColor : '#cecece',
					backgroundColor:'#e2e2e2',
					borderRadius : 5,
					borderWidth : 1,
				});
								
				var lblocation1 = Ti.UI.createLabel({
					height : 40,
					text : '所在地 : ',
					left : 10,
					top: 0,
					color:'#333',
					font : {fontSize : 14}
				});
				var lblocation2 = Ti.UI.createLabel({
					height : 40,
					text : info.location,
					left : 80,
					top: 0,
					color:'#01537b',
					font : {fontSize : 14}
				});
				pro_view.add(lblocation1);
				pro_view.add(lblocation2);
				
				//添加横线
				var line1 = Util.CreateLine({				
					height :'1',
					width : '100%',
					backgroundColor : '#cecece',})
					
				pro_view.add(line1);
				
				var lbdescription1 = Ti.UI.createLabel({
					height : 40,
					text : '自我介绍 : ',
					left : 10,
					top : 40,
					color:'#333',
					font : {fontSize : 14}
				});
				var lbdescription2 = Ti.UI.createLabel({
					height : 40,
					text : info.description,
					left : 80,
					top : 40,
					color:'#01537b',
					font : {fontSize : 14}
				});
				pro_view.add(lbdescription1);
				pro_view.add(lbdescription2);
				ProfileWin.win.add(pro_view);
				
				var procount_view = Ti.UI.createView({
					left : 10,
					right : 10,
					top : 160,
					height : 'auto',
					borderColor : '#cecece',
					backgroundColor:'#e2e2e2',
					borderRadius : 5,
					borderWidth : 1,
					layout:'absolute',
					});
				
				var gz = Ti.UI.createView({
					left:10,
					height:50,
					top:0,
					width:140,
				});
				var lb3 = Ti.UI.createLabel({
					text : '关注',
					color:'#333',
					top:5,
					width:'auto',
					height:'auto',
					font : {fontSize : 16}
				});
				gz.add(lb3);
				var lbvvalue3 = Ti.UI.createLabel({
					text : info.friends_count,
					color:'#01537b',
					top:25,
					width:'auto',
					height:'auto',
					font : {fontSize : 14}
				});
				gz.add(lbvvalue3);
				
				
				var wb = Ti.UI.createView({
					left:150,
					height:50,
					width:140,
					top:0,
				});
				var lb4 = Ti.UI.createLabel({
					text : '微薄',
					top:5,
					color:'#333',
					width:'auto',
					height:'auto',
					font : {fontSize : 16}
				});
				var lbvalue4 = Ti.UI.createLabel({
					text : info.statuses_count,
					top:25,
					color:'#01537b',
					width:'auto',
					height:'auto',
					font : {fontSize : 14}
				});
				wb.add(lb4);
				wb.add(lbvalue4);
				
				var fs = Ti.UI.createView({
					left:10,
					height:50,
					width:140,
					top : 50,
				});
				var lb5 = Ti.UI.createLabel({
					width:'auto',
					height:'auto',
					text : '粉丝',
					color:'#333',
					top:5,
					font : {fontSize : 16}
				});
				var lbvalue5 = Ti.UI.createLabel({
					width:'auto',
					height:'auto',
					text : info.friends_count,
					color:'#01537b',
					top:25,
					font : {fontSize : 14}
				});
				fs.add(lb5);
				fs.add(lbvalue5);
				
				var ht = Ti.UI.createView({
					left:150,
					height:50,
					width:140,
					top : 50,
				});
				var lb6 = Ti.UI.createLabel({
					width:'auto',
					height:'auto',
					text : '话题',
					top:5,
					color:'#333',
					font : {fontSize : 16}
				});
				var lbvalue6 = Ti.UI.createLabel({
					width:'auto',
					height:'auto',
					text : info.favourites_count,
					top:25,
					color:'#01537b',
					font : {fontSize : 14}
				});
				ht.add(lb6);
				ht.add(lbvalue6);
				
				procount_view.add(gz);
				procount_view.add(Util.CreateLine({height:'100%',width:'1',backgroundColor:'#cecece',left:150}));
				procount_view.add(wb);
				procount_view.add(Util.CreateLine({height:1,width:'100%',backgroundColor:'#cecece',top:51}));
				procount_view.add(fs);
				procount_view.add(Util.CreateLine({height:'100%',width:'1',backgroundColor:'#cecece',left:150}));
				procount_view.add(ht);
				ProfileWin.win.add(procount_view);
					
				//添加互粉按钮
				var hf = Ti.UI.createButton({
					title : '互相关注',
					backgroundImage:'images/form/statuses/button_comment_on.png',
					width:'80px',
					height:28,
					top:300,
					left:50,
					font : {fontSize : 14},
				});
				//取消关注
				var qxgz = Ti.UI.createButton({
					title : '取消关注',
					backgroundImage:'images/form/statuses/button_comment_on.png',
					width:'80px',
					height:28,
					right:10,
					top:300,
					right:50,
					font : {fontSize : 14},
				});
				ProfileWin.win.add(hf);
				ProfileWin.win.add(qxgz);
				
			};
			profileView();
			
			MeumWin.currentTab.open(ProfileWin.win,{animated:true,fullscreen:true,navBarHidden:true});
		}	
	}
	
	/**
	 * 设置父窗体
	 * @param parentWin 父窗体
	 */
	if(typeof ProfileWin.SetParentWin !== 'function')
	{
		ProfileWin.SetParentWin = function(parentWin)
		{
			if(parentWin)
			{
				ProfileWin.parentwin = parentWin;
			}
			else
			{
				Ti.API.log('LoginWin.SetParentWin:发生异常！参数parentWin不能为空!');
			}
			
		}
	}
	
	/**
	 * 根据当前用户的uid获取用户的个人信息
	 */
	if(typeof ProfileWin.Init !== 'function')
	{
		ProfileWin.Init = function(parentWin,uid)
		{
			ProfileWin.SetParentWin(parentWin);
			ProfileWin.uid = uid;
			ProfileHandler.ShowInfo(uid,parentWin);
		}
	}
	
	/**
	 * 更换UID,直接更新当前页面的内容
	 */
	if(typeof ProfileWin.SetUID !== 'function')
	{
		ProfileWin.SetUID = function(uid)
		{
			ProfileWin.uid = uid;
			var resultInfo = SinaModel.GetUserByUID(ProfileWin.uid, null);	
			
			//设置窗体上所有控件的属性
			
			
		}
	}
	
	
}())

//SinaApp.ProfileWin = ProfileWin;
